#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    setupUI();

    connect(btnStart, &QPushButton::clicked, this, [this]{
                if(!worker || !worker->isRunning()) {
                    worker = new WorkerThread(this); // 设置主窗口为parent
                    worker->start();
                }
    });
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::setupUI() {
    resize(400, 300);
    textEdit = new QPlainTextEdit(this);
    textEdit->setReadOnly(true);

    btnStart = new QPushButton("Start Thread", this);
    btnStart->setGeometry(10, 250, 120, 30);
}

